
package com.yami.shop.bean.enums;

public enum OrderStatus {

    //美团配送
    CREATED(0, "待调度"),
    ACCEPTED(20, "已接单"),
    FETCHED(30, "已取货"),
    DELIVERED(50, "已送达"),
    CANCELED(99, "已取消"),

    /**
     * 没有付款.待付款
     */
    UNPAY(1),

    /**
     * 已经付款,但卖家没有发货.待发货
     */
    PADYED(2),

    /**
     * 发货，导致实际库存减少，没有确认收货.待收货
     */
    CONSIGNMENT(3),

    /**
     * 收货，没有评价.待评价
     */
    CONFIRM(4),

    /**
     * 评价后交易成功，购买数增加1.
     */
    SUCCESS(5),

    /**
     * 订单关闭.,还原库存
     */
    CLOSE(7);

//    /**
//     * 退款审核
//     */
//    REFUND(7),
//    /**
//     * 退款成功，还原库存
//     */
//    REFUNDSUCESS(8),
//    /**
//     * 退款失败
//     */
//    REFUNDDEFAULT(9);

    private Integer num;

    public Integer value() {
        return num;
    }

    private int code;
    private String description;

    OrderStatus(Integer num) {
        this.num = num;
    }

    public static OrderStatus instance(Integer value) {
        OrderStatus[] enums = values();
        for (OrderStatus statusEnum : enums) {
            if (statusEnum.value().equals(value)) {
                return statusEnum;
            }
        }
        return null;
    }

    private OrderStatus(int code, String description) {
        this.code = code;
        this.description = description;
    }

    public static OrderStatus findByCode(int code) {
        for (OrderStatus type : OrderStatus.values()) {
            if (type.getCode() == code) {
                return type;
            }
        }
        return null;
    }

    public int getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

}
